﻿using Entitys.Models.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Common.Result.CommonError;

namespace Common.Result
{
    public class CommonError : ErrorCaseBase<CommonErrorCodeEnum>
    {
        internal override string Translate(CommonErrorCodeEnum code)
        {
            return code switch
            {
                CommonErrorCodeEnum.SUCCESS => "操作成功",

                CommonErrorCodeEnum.ThrowException => "出现内部错误:[{0}]",

                CommonErrorCodeEnum.ParamError => "参数[{0}:{1}]错误",

                CommonErrorCodeEnum.GetContentFromError => "类型[{0}]调用了ZErrorResult类的GetContent方法，请检查代码",

                CommonErrorCodeEnum.ThrowErrorFromSuccess => "类型[{0}]调用了ZSucessResult类的GetContent方法，请检查代码",

                CommonErrorCodeEnum.UndefineError => "发生未定义错误，[{0}]",

                _ => code.ToString()
            };
        }

        public enum CommonErrorCodeEnum
        {
            SUCCESS,

            /// <summary>
            /// 需要1个message参数
            /// <para>0:Exception错误提示</para>
            /// </summary>
            [Description("出现Exception异常")]
            ThrowException,

            /// <summary>
            /// 需要2个message参数
            /// <para>0:参数名称</para>
            /// <para>1:参数值</para>
            /// </summary>
            [Description("某个参数出现错误")]
            ParamError,

            /// <summary>
            /// 需要1个message参数
            /// <para>0:类型名称</para>
            /// </summary>
            [Description("调用了ZErrorResult类的GetContent方法")]
            GetContentFromError,

            /// <summary>
            /// 需要1个message参数
            /// <para>0:类型名称</para>
            /// </summary>
            [Description("调用了ZSucessResult类的GetContent方法")]
            ThrowErrorFromSuccess,

            /// <summary>
            /// 需要1个message参数
            /// <para>0:错误描述</para>
            /// </summary>
            [Description("出现Exception异常错误")]
            UndefineError,
        }
    }

    public class CommonErrorEnumeration : ErrorEnumeration
    {
        #region 错误代码
        public static CommonErrorEnumeration Success = new(0, nameof(Success));
        public static CommonErrorEnumeration ThrowException = new(1, nameof(ThrowException));
        public static CommonErrorEnumeration ParamError = new(2, nameof(ParamError));
        public static CommonErrorEnumeration UndefineError = new(3, nameof(UndefineError));
        #endregion

        public CommonErrorEnumeration(int errorCode, string errorName) : base(errorCode, errorName)
        {
        }

        public override string ErrorArea => "Common";

        protected override string Translate<T>()
        {
            throw new NotImplementedException();
        }
    }
}
